package com.ruoyi.web.controller.mine;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mine.domain.MyReserve;
import com.ruoyi.mine.service.IMyReserveService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 我的预约Controller
 *
 * @author ruoyi
 * @date 2024-07-25
 */
@Anonymous
@RestController
@RequestMapping("/mine/reserve")
public class MyReserveController extends BaseController
{
    @Autowired
    private IMyReserveService myReserveService;

    /**
     * 查询我的预约列表
     */
//    @PreAuthorize("@ss.hasPermi('mine:reserve:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyReserve myReserve)
    {
        startPage();
        List<MyReserve> list = myReserveService.selectMyReserveList(myReserve);
        return getDataTable(list);
    }

    /**
     * 导出我的预约列表
     */
//    @PreAuthorize("@ss.hasPermi('mine:reserve:export')")
    @Log(title = "我的预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MyReserve myReserve)
    {
        List<MyReserve> list = myReserveService.selectMyReserveList(myReserve);
        ExcelUtil<MyReserve> util = new ExcelUtil<MyReserve>(MyReserve.class);
        util.exportExcel(response, list, "我的预约数据");
    }

    /**
     * 获取我的预约详细信息
     */
//    @PreAuthorize("@ss.hasPermi('mine:reserve:query')")
    @GetMapping(value = "/{reserveId}")
    public AjaxResult getInfo(@PathVariable("reserveId") Long reserveId)
    {
        return success(myReserveService.selectMyReserveByReserveId(reserveId));
    }

    /**
     * 新增我的预约
     */
//    @PreAuthorize("@ss.hasPermi('mine:reserve:add')")
    @Log(title = "我的预约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyReserve myReserve)
    {
        return toAjax(myReserveService.insertMyReserve(myReserve));
    }

    /**
     * 修改我的预约
     */
//    @PreAuthorize("@ss.hasPermi('mine:reserve:edit')")
    @Log(title = "我的预约", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyReserve myReserve)
    {
        return toAjax(myReserveService.updateMyReserve(myReserve));
    }

    /**
     * 删除我的预约
     */
//    @PreAuthorize("@ss.hasPermi('mine:reserve:remove')")
    @Log(title = "我的预约", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reserveIds}")
    public AjaxResult remove(@PathVariable Long[] reserveIds)
    {
        return toAjax(myReserveService.deleteMyReserveByReserveIds(reserveIds));
    }
}
